package controllers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedProperty;

import beans.HistoryBeanRemote;
import dto.HistoryDTO;

/**
 * Managed Bean pentru lista de inregistrari la istoria unei resurse
 *  
 * @author zahariem
 */
public class ListHistoryController implements Serializable{
	
	private static final long serialVersionUID = 1L;

	@EJB
	HistoryBeanRemote historyBR;
	
	@ManagedProperty(value = "${history}")
	HistoryDTO histDTO;
	
	private List<HistoryDTO> listH = new ArrayList<HistoryDTO>();
	private boolean show=false; 
	

	public HistoryDTO getHistDTO() {
		return histDTO;
	}

	public void setHistDTO(HistoryDTO histDTO) {
		this.histDTO = histDTO;
	}

	public ListHistoryController() {
	}
	
	/**
	 * Populeaza lista de inreg. din history pentru resursa cu id-ul primit ca parametru  
	 * 
	 * @author zahariem
	 * 
	 * @param idSource este de tip String ca sa poata fi apelata din pagina xhtml
	 * @return nu este necesar decat sa se potriveasca cu metodele apelabile in pagina xhtml 
	 * 
	 */
	public String loadHistory(String idSource){
		int idSource1 = Integer.parseInt(idSource);
		this.listH = historyBR.allHistoryToSource(idSource1);
		if(listH.size() > 0){
			this.show=true;
		}
		else{
			this.show=false;
		}
		
		return "ok";
	}	

	public List<HistoryDTO> getListH() {
		return listH;
	}

	public void setListH(List<HistoryDTO> listH) {
		this.listH = listH;
	}
	public boolean isShow() {
		return show;
	}

	public void setShow(boolean show) {
		this.show = show;
	}
}
